const dynamic = require('../model/dynamic')

exports.add = async (req, res, next) => {
  try {
    const data = await dynamic.add(req.body)
    res.status(201).json({
      data
    })
  } catch (err) {
    next(err)
  }
}

exports.update = async (req, res, next) => {
  try {
    const data = await dynamic.update(req.body)
    res.status(200).json({msg: '更新成功', data })
  } catch (error) {
    next(error)
  }
}

exports.remove = async (req, res, next) => {
  try {
    const data = await dynamic.remove(req.params.id || '')
    res.status(200).json({msg: '删除成功', data })
  } catch (error) {
    next(error)
  }
}

exports.list = async (req, res, next) => {
  try {
    const data = await dynamic.list()
    res.status(200).json(data)
  } catch (err) {
    next(err)
  }
}

exports.detail = async (req, res, next) => {
  try {
    const data = await dynamic.detail(req.params.id || '')
    res.status(200).json(data)
  } catch (err) {
    next(err)
  }
}

exports.showIndex = (req, res, next) => {
  try {
    res.render('dynamic/index')
  } catch (error) {
    next(error)
  }
}

exports.showAdd = (req, res, next) => {
  try {
    res.render('dynamic/detail', {id: req.params.id || ''})
  } catch (error) {
    next(error)
  }
} 

exports.showEdit = (req, res, next) => {
  try {
    res.render('dynamic/detail', {id: req.params.id || ''})
  } catch (error) {
    next(error)
  }
} 